let aID = window.location.href.split('=')[1]
let lyricObj = []
$.get(`http://192.168.5.120:8089/song/url?id=${aID}`, () => {
	$('#audio').attr('src', `https://music.163.com/song/media/outer/url?id=${aID}.mp3`)
})
$.get(`http://192.168.5.120:8089/lyric?id=${aID}`, res => {

	// console.log(res);
	var lrc = res.lrc.lyric.split('\n')
	var timeReg = /\[\d*\:\d*\.\d*\]/
	$.each(lrc, (index, item) => {
		// console.log(item);
		// 处理歌词和时间
		var lyrictime = item.match(timeReg)

		var lyric = item.replace(timeReg, '')
		if (!lyric) {
			return
		} else {
			var minute = Number(lyrictime[0].match(/\[\d*/)[0].replace('[', ''))
			console.log(minute);
			// 秒
			var s = Number(lyrictime[0].match(/:\d*\.\d*/)[0].replace(':', ''))
			let time = minute * 60 + s
			lyricObj.push({
				time,
				lyric
			})
			$('.lyrics-bpx').append(`<p class="lyrics-mid">
				${lyric}</p>`)
		}
	})
	var audio = document.querySelector('#audio')
	$(audio).bind('timeupdate', () => {
		$.each(lyricObj, (index, item) => {
			if (item.time < audio.currentTime) {
				$('.lyrics-bpx p').eq(index).addClass('highlight').siblings().removeClass('highlight')
			}

		})
	})
})